package com.hhkj.api.commission.service.biz.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.hhkj.admin.sale.model.dopo.SaleCommissionCountPo;
import com.hhkj.admin.sale.model.dopo.SaleCommissionPo;
import com.hhkj.admin.sale.service.base.SaleCommissionService;
import com.hhkj.api.commission.model.req.ApiCommissionPagingReq;
import com.hhkj.api.commission.model.res.ApiCommissionPagingRes;
import com.hhkj.api.commission.model.res.ApiSaleCommissionCountRes;
import com.hhkj.api.commission.service.biz.ApiSaleCommissionBizService;
import com.hhkj.api.sale.common.session.holder.ApiSaleSessionHolder;
import com.ruoyi.common.utils.paging.PageInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ApiSaleCommissionBizServiceImpl
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/11/6 9:59
 */
@Service
public class ApiSaleCommissionBizServiceImpl
        implements ApiSaleCommissionBizService {

    @Autowired
    private SaleCommissionService commissionService;

    @Override
    public PageInfo<ApiCommissionPagingRes> paging(ApiCommissionPagingReq req) {
        Long saleId = ApiSaleSessionHolder.getSaleId();
        req.setSaleId(saleId);
        List<SaleCommissionPo> commissionPoList = commissionService.listPoByDo(req);
        return PageInfoUtils.toPageInfo(commissionPoList, ApiCommissionPagingRes.class);
    }

    @Override
    public ApiSaleCommissionCountRes count() {
        Long saleId = ApiSaleSessionHolder.getSaleId();
        SaleCommissionCountPo countPo = commissionService.countPriceBySaleId(saleId);
        return BeanUtil.toBean(countPo, ApiSaleCommissionCountRes.class);
    }
}
